import api from '../../api/api.js'
import util from '../../utils/util.js'
import load from '../templates/loader/loader.js'
var app = getApp()
console.log("222")
Page({
  data: {
    banner: {},
    height: 0,
    currentTab: 0,
    itemData: []
  },
  onLoad: function () {
    var that = this
    //初始化载入等待动画
    that.loader = load.loader(that, {
      size: 50,
      borderWidth: 3
    });
    that.loader.open();
    //获取屏幕高度
    util.autoHeight(function (res) {
      that.setData({
        height: res
      })
    })
    that.loadData();
  },
  loadData: function (callback) {
    var that = this;
    // 加载首页
    var jsonStr='{"REQ_HEAD": {"SIGN": "null"},"REQ_BODY": {"classifyId":""}}';
    api.indexView({
      method: 'POST',
      data: {
        REQ_MESSAGE: jsonStr
      },
      success: (res) => {
        that.setData({
          banner: res.rows[0].carouselFigureV,
          itemData: res.rows[0].classifyV
        });
      },
      fail: (res) => {
        that.loader.open(api.statusFail.title);
      },
      complete: (res) => {
        that.loader.close();
        if (res.errMsg == "request:fail timeout") {
          that.loader.open("连接超时");
        }
        if (typeof callback == "function") {
          callback();
        }
      }
    })
  },
  switchTab: function (e) {
    var tag = e;
    this.setData({
      currentTab: tag.detail.current
    });
  },
  switchSwiper: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.index
    })
  },
  onShareAppMessage:function(){

  },
  onPullDownRefresh: function () {
    // wx.showNavigationBarLoading() //在标题栏中显示加载
    // this.loadData(function () {
    //   wx.hideNavigationBarLoading() //完成停止加载
    //   wx.stopPullDownRefresh() //停止下拉刷新
    // });
    // setTimeout(function () {
    //   wx.hideNavigationBarLoading() //完成停止加载
    //   wx.stopPullDownRefresh() //停止下拉刷新
    // }, 10000);
  }
})